home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.app;
-
- import com.extensibility.app.plugin.URIResourcePlugin;
- import com.extensibility.plugin.PluginRegistry;
- import com.extensibility.plugin.api.ApplicationAccess;
- import com.extensibility.rock.AltGrPatch;
- import com.extensibility.rock.Platform;
- import com.extensibility.rock.RDialog;
- import com.extensibility.util.Debug;
- import com.extensibility.util.Security;
- import com.extensibility.xml.URI;
- import com.extensibility.xml.URIFileScheme;
- import com.extensibility.xml.URIStringScheme;
- import com.extensibility.xml.URIUrlScheme;
- import com.extensibility.xml.URIUrnScheme;
- import com.extensibility.xml.URIxschemaScheme;
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.Frame;
- import java.awt.Window;
- import java.awt.event.ActionEvent;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.io.Writer;
- import java.net.URL;
- import java.util.Date;
- import java.util.Enumeration;
- import java.util.EventObject;
- import java.util.Vector;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.UIManager;
-
- public abstract class BaseApplication implements Platform.Application {
- static final String PRINT_TEMPLATE = "_print_template";
- protected static BaseApplication oneAndOnly;
- // $FF: renamed from: ui com.extensibility.app.UI
- static UI field_0;
- private final Registration newreg = new Registration(this);
- protected Security registration;
- private ApplicationPreferences prefs;
- protected Vector listeners = new Vector();
- static File homePath;
- private ApplicationAccess pluginAppAccess = new 1();
- BaseAction showHideToolbarAction;
- // $FF: synthetic field
- static Class class$com$extensibility$app$BaseApplication;
-
- public BaseApplication() {
- new AltGrPatch();
- oneAndOnly = this;
- }
-
- public static BaseApplication getApplication() {
- return oneAndOnly;
- }
-
- public static String getPreference(String var0) {
- return getApplication().prefs.getProperty(var0);
- }
-
- public static ApplicationPreferences getPreferences() {
- return getApplication().prefs;
- }
-
- public static String getPreference(String var0, int var1) {
- return getApplication().prefs.getProperty(var0 + var1);
- }
-
- public static UI getUI() {
- return field_0;
- }
-
- public static boolean isDebug() {
- if (getPreferences() != null) {
- return getPreferences().getDebugLevel() > 0;
- } else {
- return true;
- }
- }
-
- public static int getDebugLevel() {
- return getPreferences() != null ? getPreferences().getDebugLevel() : 2;
- }
-
- public static File getHomePath() {
- if (homePath != null) {
- return homePath;
- } else {
- String var0 = System.getProperty("java.class.path");
-
- while(var0 != null) {
- int var2 = var0.indexOf(System.getProperty("path.separator"));
- String var1;
- if (var2 >= 0) {
- var1 = var0.substring(0, var2);
- var0 = var0.substring(var2 + 1);
- } else {
- var1 = var0;
- var0 = null;
- }
-
- if (var1.length() != 0) {
- File var3 = new File(var1);
- if (var3.isDirectory()) {
- if ((new File(var1, (class$com$extensibility$app$BaseApplication != null ? class$com$extensibility$app$BaseApplication : (class$com$extensibility$app$BaseApplication = class$("com.extensibility.app.BaseApplication"))).getName().replace('.', File.separatorChar) + ".class")).exists()) {
- homePath = new File(var3.getParent());
- break;
- }
- } else if (var3.getName().equalsIgnoreCase(getApplication().getAbbr() + ".jar")) {
- String var4 = var3.getParent();
- if (var4 == null) {
- var4 = System.getProperty("user.dir");
- }
-
- homePath = new File(var4);
- break;
- }
- }
- }
-
- Debug.assert(homePath != null, "Unable to locate home path within " + System.getProperty("java.class.path") + ". Looked for: " + getApplication().getAbbr() + ".jar");
- return homePath;
- }
- }
-
- public void reregister() {
- this.newreg.reregister();
- }
-
- public static Date getExpiration() {
- return Registration.getExpirationDate();
- }
-
- private void register() {
- this.newreg.register();
- }
-
- public void openDocumentList(String[] var1) {
- for(int var2 = 0; var2 < var1.length; ++var2) {
- if (!var1[var2].equals("-quiet")) {
- if (var1[var2].charAt(0) == '"' && var1[var2].charAt(var1[var2].length() - 1) == '"') {
- var1[var2] = var1[var2].substring(1, var1[var2].length() - 1);
- }
-
- this.openDocument(new File(var1[var2]));
- }
- }
-
- }
-
- public void doArgs(String[] var1) {
- if (var1 != null && var1.length > 0 && var1[0].length() > 0) {
- Desktop.createSplash();
- Desktop.createWelcome(false);
- this.openDocumentList(var1);
- } else if (getPreferences().getShowWelcome()) {
- Desktop.createWelcome(true);
- this.preflight();
- } else {
- Desktop.createSplash();
- Desktop.createWelcome(false);
- this.newDocument((EventObject)null);
- }
-
- this.fireApplicationStarted();
- }
-
- protected String[] getSaveTypes() {
- return this.getOpenTypes();
- }
-
- public abstract byte getRegVersion();
-
- protected abstract String[] getOpenTypes();
-
- public abstract BaseDocument createNewDocument(EventObject var1);
-
- public abstract BaseDocument createNewDocument(URI var1);
-
- protected abstract UI createUI();
-
- protected abstract Class getMainWindowClass();
-
- protected abstract BaseWindow createNewWindow(BaseDocument var1);
-
- protected abstract ApplicationPreferences createPreferences();
-
- protected abstract String getAbbr();
-
- public abstract String getVersion();
-
- public RDialog createPreferencesDialog(JFrame var1) {
- return new PreferencesDialog(var1, getPreferences());
- }
-
- public abstract JFrame createWelcome();
-
- public abstract RDialog createPrintDialog(Frame var1);
-
- public void startup() throws Exception {
- field_0 = this.createUI();
- field_0.initResources();
- Platform.initialize(this);
- this.prefs = this.createPreferences();
- this.prefs.readInitial(new File(getHomePath(), this.getAbbr() + "_Preferences"));
- Font var1 = this.prefs.getAppFont();
- if (var1 != null) {
- UI.setAppFont(var1);
- }
-
- var1 = this.prefs.getDocFont();
- if (var1 != null) {
- UI.setDocFont(var1);
- }
-
- var1 = this.prefs.getSrcFont();
- if (var1 != null) {
- UI.setSrcFont(var1);
- }
-
- try {
- String var2 = this.prefs.getLookAndFeel();
- UIManager.setLookAndFeel(var2);
- } catch (Exception var3) {
- }
-
- Debug.setCatcher(this.createCatcher());
- this.doPluginRegistration();
- this.register();
- this.registration = this.newreg.getRegistration();
- if (getDebugLevel() > 1) {
- System.setOut(new PrintStream(new FileOutputStream(new File("console-out.txt"))));
- System.setErr(new PrintStream(new FileOutputStream(new File("console-err.txt"))));
- }
-
- if (this.newreg.isLaunchLimited()) {
- this.prefs.updateLaunchesLeft(this.prefs.getLaunchesLeft() - 1);
- }
-
- }
-
- protected void doPluginRegistration() {
- String var1 = UI.getString("plugin.folder");
- if (var1.startsWith("#MISSING")) {
- var1 = "plugins";
- }
-
- File var2 = new File(getHomePath(), var1);
- PluginRegistry var3 = PluginRegistry.getRegistry();
- var3.setAppAccess(this.pluginAppAccess);
- var3.registerPluginsInFolder(var2);
- URIResourcePlugin.registerPlugin(var3);
- URIFileScheme.registerPlugin(var3);
- URIStringScheme.registerPlugin(var3);
- URIUrlScheme.registerPlugin(var3);
- URIUrnScheme.registerPlugin(var3);
- URIxschemaScheme.registerPlugin(var3);
- URI.registerSchemes();
- }
-
- protected Debug.Catcher createCatcher() {
- return new 2();
- }
-
- public void quit() {
- this.exitApplication((EventObject)null);
- }
-
- public void openAboutWindow() {
- Desktop.createAboutWindow();
- }
-
- public void printDocument(File var1) {
- }
-
- public void exitApplication(EventObject var1) {
- Vector var2 = Desktop.getWindows();
-
- for(int var3 = var2.size() - 1; var3 >= 0; --var3) {
- BaseWindow var4 = (BaseWindow)var2.elementAt(var3);
- if (!var4.getDocument().isOkToClose(var4)) {
- return;
- }
- }
-
- for(int var8 = var2.size() - 1; var8 >= 0; --var8) {
- BaseWindow var5 = (BaseWindow)var2.elementAt(var8);
- ((Frame)var5).dispose();
- }
-
- try {
- this.prefs.save();
- } catch (IOException var6) {
- DialogFactory.showException((Component)null, 108, var6);
- } catch (Throwable var7) {
- Debug.assert(false, "Got a non io error exiting application: " + var7);
- }
-
- this.fireApplicationExited();
- System.exit(0);
- }
-
- private void preflight() {
- }
-
- public static boolean isLaunchLimited() {
- return getApplication().newreg.isLaunchLimited();
- }
-
- public static int getLaunchesLeft() {
- return getApplication().prefs.getLaunchesLeft();
- }
-
- public boolean openDocumentURL(ActionEvent var1) {
- String[] var2 = this.getOpenTypes();
- String var3 = getPreferences().getOpenFromBase();
- URI var4 = null;
- if (var3 != null) {
- var4 = new URI((URI)null, var3);
- }
-
- URI var5 = DialogFactory.openURI(Desktop.getDialogParent(var1), var4, var2);
- if (var5 == null) {
- return false;
- } else {
- this.openDocument(var5);
- return true;
- }
- }
-
- public boolean saveDocumentTo(ActionEvent var1, BaseDocument var2) {
- Object var3 = null;
- String var4 = getPreferences().getSaveToBase();
- URI var5 = var2.getURI();
- String var6 = var5.getFullName();
- if (var6.length() < 0 || var4 != null && var4.length() != 0 && var5.getScheme().equals("file")) {
- String var7 = var2.getName();
- if (var4 == null) {
- var4 = var7;
- } else {
- if (!var4.endsWith("/")) {
- var4 = var4 + "/";
- }
-
- var4 = var4 + var7;
- }
- } else {
- var4 = var6;
- }
-
- URI var12 = new URI((URI)null, var4);
- URI var8 = DialogFactory.saveURI(Desktop.getDialogParent(var1), var12, (String[])var3);
- if (var8 == null) {
- return false;
- } else if (var8.exists() && !DialogFactory.showConfirm((Component)null, UI.getString("stop.uri.exists", var8.getFullName()), UI.getString("dialog.replace.title"))) {
- return false;
- } else {
- try {
- Writer var9 = var2.createWriter(var8);
- var2.write(var9);
- var9.close();
- return true;
- } catch (Exception var10) {
- DialogFactory.showException((Component)null, 103, var10, var8.getShortName());
- return false;
- }
- }
- }
-
- public BaseDocument newDocument(EventObject var1) {
- BaseDocument var2 = this.createNewDocument(var1);
-
- try {
- BaseWindow var3 = this.getMainWindow(var2);
- ((Component)var3).setVisible(true);
- } catch (Exception var5) {
- String var4 = Platform.mapNewlinesForTextArea(Debug.getStackTrace(var5));
- JOptionPane.showMessageDialog(new JFrame(), var4);
- Desktop.ensureWindow();
- }
-
- return var2;
- }
-
- public boolean openDocument(URI var1) {
- BaseDocument var2 = Desktop.getDocument(var1);
- if (var2 != null) {
- DialogFactory.stop((Component)null, UI.getString("stop.already.open", var1.getShortName()));
- Desktop.activateDocument(var2);
- return true;
- } else {
- BaseDocument var3 = this.createNewDocument(var1);
-
- try {
- var3.read(var1);
- this.updateFileLists(var1);
- this.getMainWindow(var3);
- this.fireDocumentOpened(var1);
- return true;
- } catch (Exception var5) {
- DialogFactory.showException((Component)null, 102, var5);
- return false;
- }
- }
- }
-
- public BaseWindow getMainWindow(BaseDocument var1) {
- BaseWindow var2 = var1.getWindow(this.getMainWindowClass());
- if (var2 != null) {
- ((Window)var2).toFront();
- return var2;
- } else {
- var2 = this.createNewWindow(var1);
- Desktop.positionNewWindow(var2);
- var2.initialize(getPreferences());
- Desktop.showNewWindow(var2, true);
- return var2;
- }
- }
-
- public void createAnotherWindow(BaseDocument var1) {
- BaseWindow var2 = this.createNewWindow(var1);
- Desktop.positionNewWindow(var2);
- var2.initialize((ApplicationPreferences)null);
- Desktop.showNewWindow(var2, false);
- }
-
- public boolean openDocument(ActionEvent var1) {
- File var2 = DialogFactory.askFile(Desktop.getDialogParent(var1), UI.getString("dialog.open.schema"), this.getOpenTypes());
- return var2 == null ? false : this.openDocument(new URI(var2));
- }
-
- public void saveNotify(URI var1, BaseDocument var2) {
- Enumeration var3 = Desktop.getDocuments();
-
- while(var3.hasMoreElements()) {
- BaseDocument var4 = (BaseDocument)var3.nextElement();
- if (var4 != var2) {
- var4.saveNotify(var1);
- }
- }
-
- this.fireDocumentSaved(var1);
- }
-
- public void updateFileLists(URI var1) {
- this.prefs.updateRecent(var1);
- this.updateRecentMenu();
- this.updateWindowMenu();
- }
-
- public void removeFromRecent(URI var1) {
- this.prefs.removeFromRecent(var1);
- this.updateRecentMenu();
- }
-
- private void updateWindowMenu() {
- Enumeration var1 = Desktop.getWindows().elements();
-
- while(var1.hasMoreElements()) {
- BaseWindow var2 = (BaseWindow)var1.nextElement();
- var2.fillWindowsMenu();
- }
-
- }
-
- private void updateRecentMenu() {
- Enumeration var1 = Desktop.getWindows().elements();
-
- while(var1.hasMoreElements()) {
- BaseWindow var2 = (BaseWindow)var1.nextElement();
- var2.updateRecentMenuItems();
- }
-
- }
-
- public void updateNewSubMenu() {
- Enumeration var1 = Desktop.getWindows().elements();
-
- while(var1.hasMoreElements()) {
- BaseWindow var2 = (BaseWindow)var1.nextElement();
- String var3 = getPreferences().getDefaultFileType();
- var2.updateNewSubMenuItems(UI.getFileTypeName(var3));
- }
-
- }
-
- public BaseAction createToolbarAction() {
- if (this.showHideToolbarAction == null) {
- this.showHideToolbarAction = new 3(this, "item.tb");
- this.showHideToolbarAction.setSelected(this.prefs.getToolbarView() == 1);
- }
-
- return this.showHideToolbarAction;
- }
-
- private void updateToolBarView(int var1) {
- this.prefs.updateToolBarView(var1);
- Enumeration var2 = Desktop.getWindows().elements();
-
- while(var2.hasMoreElements()) {
- BaseWindow var3 = (BaseWindow)var2.nextElement();
- var3.updateToolBarView();
- }
-
- }
-
- public boolean openDocument(URL var1) {
- return this.openDocument(new URI(var1));
- }
-
- public boolean openDocument(File var1) {
- return this.openDocument(new URI(var1));
- }
-
- public void addApplicationListener(ApplicationListener var1) {
- this.listeners.addElement(var1);
- }
-
- public void removeApplicationListener(ApplicationListener var1) {
- this.listeners.removeElement(var1);
- }
-
- public void fireApplicationStarted() {
- Enumeration var1 = this.listeners.elements();
-
- while(var1.hasMoreElements()) {
- ApplicationListener var2 = (ApplicationListener)var1.nextElement();
- var2.applicationStarted();
- }
-
- }
-
- public void fireApplicationExited() {
- Enumeration var1 = this.listeners.elements();
-
- while(var1.hasMoreElements()) {
- ApplicationListener var2 = (ApplicationListener)var1.nextElement();
- var2.applicationExited();
- }
-
- }
-
- public void fireDocumentOpened(URI var1) {
- Enumeration var2 = this.listeners.elements();
-
- while(var2.hasMoreElements()) {
- ApplicationListener var3 = (ApplicationListener)var2.nextElement();
- var3.documentOpened(var1);
- }
-
- }
-
- public void fireDocumentSaved(URI var1) {
- Enumeration var2 = this.listeners.elements();
-
- while(var2.hasMoreElements()) {
- ApplicationListener var3 = (ApplicationListener)var2.nextElement();
- var3.documentSaved(var1);
- }
-
- }
-
- public void fireDocumentClosed(URI var1) {
- Enumeration var2 = this.listeners.elements();
-
- while(var2.hasMoreElements()) {
- ApplicationListener var3 = (ApplicationListener)var2.nextElement();
- var3.documentClosed(var1);
- }
-
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
- }
-
- // $FF: synthetic method
- static ApplicationPreferences access$0(BaseApplication var0) {
- return var0.prefs;
- }
-
- // $FF: synthetic method
- static void access$1(BaseApplication var0, int var1) {
- var0.updateToolBarView(var1);
- }
- }
-